import 'package:flutter/material.dart';
import 'package:magatron/develop/mine.dart';
import 'package:magatron/normal/firstpage.dart';
import 'package:magatron/notice/course.dart';

import '../const.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage>
    with SingleTickerProviderStateMixin {
  var titles = ['资讯', '服务', '我的'];
  int _currentIndex = 0;
  String nickName;
  String title = '客户';
  String memberBh = '';
  List<BottomNavigationBarItem> icons = new List();
  var _mySubscription;
  var _scaffoldkey = new GlobalKey<ScaffoldState>();
  var _controller = PageController(
    initialPage: 0,
  );

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  void initState() {
    // _memberInfo();
  }

  /*_memberInfo() async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    memberBh = sp.getString('bh');
    if (memberBh != null) {
      Map<String, dynamic> dataBind = Map();
      dataBind['memberBh'] = memberBh;
      MyDio.getInstance().clearInstance();
      MyDio.getInstance().get(Apis.memberInfo + memberBh, (data) async {
        print(data);
        if (data['resultCode'] == 0) {
          UserInfoBean _userInfoBean = UserInfoBean.fromJson(data['record']);
          sp.setString(PERSON_NUM, _userInfoBean.personNum);
          sp.setString(UUID, _userInfoBean.recordBh);
          sp.setString('loginName', _userInfoBean.loginName);
          sp.setString('nickName', _userInfoBean.nickName);
          sp.setString('photo', _userInfoBean.photo);
          sp.setString(AREA_CODE, _userInfoBean.areacode);
          print('身份证号保存成功');
        }
      });
    }
  }*/

  /*Future<bool> requestPermission() async {
    final permissions = await PermissionHandler().requestPermissions([
      PermissionGroup.location,
      PermissionGroup.sensors,
      PermissionGroup.storage,
    ]);

    if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
      return true;
    } else {
      return false;
    }
  }*/

  List<BottomNavigationBarItem> setIcons() {
    icons.clear();
    icons.add(BottomNavigationBarItem(
        icon: _currentIndex == 0
            ? Icon(Icons.home, color: gold)
            : Icon(Icons.home, color: grey),
        title: Text(
          titles[0],
        )));
    icons.add(BottomNavigationBarItem(
        icon: _currentIndex == 1
            ? Icon(Icons.drive_eta, color: gold)
            : Icon(Icons.drive_eta, color: grey),
        title: Text(
          titles[1],
        )));
    icons.add(BottomNavigationBarItem(
        icon: _currentIndex == 2
            ? Icon(Icons.person, color: gold)
            : Icon(Icons.person, color: grey),
        title: Text(
          titles[2],
        )));

    return icons;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldkey,
      backgroundColor: black,
      body: PageView(
        controller: _controller,
        children: [FirstPage(), Course(), Mine()],
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          backgroundColor: bar,
          selectedItemColor: gold,
          unselectedItemColor: grey,
          selectedFontSize: 12,
          unselectedFontSize: 12,
          onTap: (index) async {
            title = titles[index];
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });

//            _updateApp('http://issuecdn.baidupcs.com/issue/netdisk/apk/BaiduNetdisk_10.0.116.apk',false);
          },
          type: BottomNavigationBarType.fixed,
          items: setIcons()),
    );
  }
}
